use crate::fetcher::{delete, get, post, put, Callback, Fetchable, Nothing};
pub use crate::fetcher::{FetchTask, Resp};
use crate::state::{Comment, Task};

const HOST: &'static str = "http://0.0.0.0:8088/tasks/api/v1";

fn uri(suffix: &str) -> String {
    format!("{}/{}", HOST, suffix)
}

pub fn fetch_all_task(handler: Callback<Resp<Vec<Task>>>) -> Option<FetchTask> {
    get(uri("tasks")).body(Nothing).execute(handler)
}

pub fn fetch_all_comments(tid: i32, handler: Callback<Resp<Vec<Comment>>>) -> Option<FetchTask> {
    get(uri(format!("tasks/{}/comments", tid).as_str()))
        .body(Nothing)
        .execute(handler)
}
